﻿// Autore: Mattia Barrasso

using RecipesManager.Data;
using White.Core;
using White.Core.UIItems;
using White.Core.UIItems.ListBoxItems;
using White.Core.UIItems.WindowItems;

namespace RecipesManager.Specs.Ingrediente
{
    public class ReceipeManagerBdd
    {
        protected Application Application;
        protected Window MainWindow;
        protected Button _backToMainMenu;
        protected readonly string IngredientManagerTitle = "Gestione Ingredienti";

        protected Button _creaIngrediente;
        protected ListBox _ingredients;
        protected Button _chiudiButton;
        protected Button _saveButton;
        protected TextBox _ingredientName;
        protected RadioButton[] _unitButtons;
        protected ComboBox _categoriesBox;
        protected ListBox _selectedCategories;
        protected Button _addCategory;
        protected Button _removeCategory;
        protected ComboBox _shopsBox;
        protected Button _removeShop;
        protected IUIItem _selectedShops;
        protected Button _addShop;

        protected void GetIgredientsUi()
        {
            _creaIngrediente = MainWindow.Get<Button>("bt_add");
            _ingredients = MainWindow.Get<ListBox>("lb_items");
            _backToMainMenu = MainWindow.Get<Button>("bt_back");
        }

        protected void GetSingleIngredientUi()
        {
            _chiudiButton = MainWindow.Get<Button>("bt_chiudi");

            _saveButton = MainWindow.Get<Button>("bt_salva");
            _ingredientName = MainWindow.Get<TextBox>("tb_nomeIngrediente");
            _unitButtons = new RadioButton[3];
            _unitButtons[0] = MainWindow.Get<RadioButton>("rb_peso");
            _unitButtons[1] = MainWindow.Get<RadioButton>("rb_volume");
            _unitButtons[2] = MainWindow.Get<RadioButton>("rb_unita");

            _categoriesBox = MainWindow.Get<ComboBox>("cb_categorie");
            _selectedCategories = MainWindow.Get<ListBox>("lb_categorieACuiAppartiene");
            _addCategory = MainWindow.Get<Button>("bt_aggiungiCat");
            _removeCategory = MainWindow.Get<Button>("bt_cancellaCat");

            _shopsBox = MainWindow.Get<ComboBox>("cb_negozi");
            _selectedShops = MainWindow.Get<ListView>("dg_shops");
            _addShop = MainWindow.Get<Button>("bt_aggiungiNeg");
            _removeShop = MainWindow.Get<Button>("bt_cancellaNeg");
        }

        protected void SetUpScenario()
        {
            Manager.ClearDatabase();
            Manager.Measures.Add("grammi", "gr", MeasureType.Weight, MeasureFamily.Metric, 1);
            Manager.Measures.Add("PesoTest", "PT", MeasureType.Weight, MeasureFamily.Metric, 1);
            Application = Application.Launch(@"..\..\..\RecipesManager\bin\x86\WhiteTesting\RecipesManager.exe");
            MainWindow = Application.GetWindow("Recipes Manager");
        }

        protected void TearDownScenario()
        {
            Manager.ClearCache();
            Manager.ClearDatabase();
            Application.Kill();
        }

        protected void NavigateToIngredients()
        {
            MainWindow.Get<Button>("ingredienti").Click();
            MainWindow = Application.GetWindow(IngredientManagerTitle);
        }

        protected void NavigateToMainMenu()
        {
            MainWindow.Get<Button>("bt_back").Click();
            MainWindow = Application.GetWindow("Recipes Manager");
        }
    }
}